# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/27 14:22 
@Author  : ZhangShenao 
@File    : metadata.py 
@Desc    : 元数据相关的内置函数
"""

# type()函数: 获取对象的类型
t1 = type('a')
print(f't1 = {t1}')  # t1 = <class 'str'>
t2 = type([1, 2, 3])
print(f't2 = {t2}')  # t2 = <class 'list'>

# isinstance()函数: 判断对象是否是某个类型(或子类型)
is1 = isinstance('a', str)
print(f'is1 = {is1}')  # is1 = True
is2 = isinstance([1, 2, 3], list)
print(f'is2 = {is2}')  # is2 = True
is3 = isinstance(1, tuple)
print(f'is3 = {is3}')  # is3 = False
# 也可以把多个类型放在元组中,其中一个与对象的类型相符即为True,若无相符则为 False
is4 = isinstance('a', (int, list, str))
print(f'is4 = {is4}')  # is4 = True
is5 = isinstance(1, (str, list, set))
print(f'is5 = {is5}')  # is5 = False

# dir()函数: 获取类或对象中的所有方法和属性；无参数时获取当前作用域下的所有名字
dir1 = dir('a')
print(f'dir1 = {dir1}')
dir2 = dir(int)
print(f'dir2 = {dir2}')

# id()函数: 返回一个对象的唯一标识
# 在CPython中这个唯一标识实际为该对象在内存中的地址
a = 1
print(f'id of a is {id(a)}')  # id of a is 4366736456
l = [1, 2, 3]
print(f'id of l is {id(l)}')  # id of l is 4346593536
